package org.swift.mashup.engine.concurrency;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import edu.emory.mathcs.backport.java.util.Collections;

public class StaticConcurrentConfiguration implements ConcurrentConfiguration {
	private final String workingDir;
	private final ArrayList<String> computeNodes = new ArrayList<String>();
	private final String contextType = "local";
	
	public StaticConcurrentConfiguration (String[] computeNodes){
		workingDir = "";
		Collections.addAll(this.computeNodes,computeNodes);
	}
	
	public StaticConcurrentConfiguration (Collection<String> nodes){
		workingDir = "";
		computeNodes.addAll(nodes);
	}
	
	public StaticConcurrentConfiguration (Collection<String> nodes, String workingDir){
		this.workingDir = workingDir;
		computeNodes.addAll(nodes);
	}
	
	public StaticConcurrentConfiguration (String[] computeNodes, String workingDir){
		this.workingDir = workingDir;
		Collections.addAll(this.computeNodes,computeNodes);
	}
	
	public Iterator<String> getComputeNodeIterator() {
		return computeNodes.iterator();
	}

	public int computeNodeCount() {
		return computeNodes.size();
	}
	
	public static ConcurrentConfiguration newConfiguration (int numNodes){
		return newConfiguration(numNodes, null);
	}
	
	public static ConcurrentConfiguration newConfiguration (int numNodes, String workingDir){
		String[] nodes = new String[numNodes];
		for (int i = 0; i < numNodes; i++){
			nodes[i] = "nodes" + (i+1);
		}
		return new StaticConcurrentConfiguration(nodes,workingDir);
	}
	
	public String getWorkingDirectory() {
		return workingDir;
	}
	
	public String getSettingsDirectory() {
		return "/settings";
	}

	public String getContextType() {
		return contextType;
	}
	
	public int getMaxAttempts() {
		return 1;
	}
	public boolean isDeleteFiles() {
		return true;
	}

	public boolean isMappedFiles() {
		return true;
	}

}
